import {Switch,Route,Redirect} from 'react-router-dom';
import React from 'react';

function RouterView(props){
    let {routes} = props;
    console.log("routes",routes);
    let routeArr = routes.filter(item => item.component);
    let redirectArr =  routes.filter(item => !item.component);
    return <Switch>
        {/* {routeArr.map(item => <Route key={item.path} path={item.path} component={item.component}></Route>)} */}
        {routeArr.map(item => <Route key={item.path} path={item.path} render={(props) => {
            return <item.component {...props} routes={item.children}></item.component>
        }}></Route>)}
        {redirectArr.map(item => <Redirect key={item.path} from={item.path} to={item.redirect}></Redirect>)}
    </Switch>
}

export default RouterView